home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_grp.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  3KB  |  86 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''Test script for the grp module.'''
  5. import grp
  6. import unittest
  7. from test import test_support
  8.  
  9. class GroupDatabaseTestCase(unittest.TestCase):
  10.     
  11.     def check_value(self, value):
  12.         self.assertEqual(len(value), 4)
  13.         self.assertEqual(value[0], value.gr_name)
  14.         self.assert_(isinstance(value.gr_name, basestring))
  15.         self.assertEqual(value[1], value.gr_passwd)
  16.         self.assert_(isinstance(value.gr_passwd, basestring))
  17.         self.assertEqual(value[2], value.gr_gid)
  18.         self.assert_(isinstance(value.gr_gid, int))
  19.         self.assertEqual(value[3], value.gr_mem)
  20.         self.assert_(isinstance(value.gr_mem, list))
  21.  
  22.     
  23.     def test_values(self):
  24.         entries = grp.getgrall()
  25.         for e in entries:
  26.             self.check_value(e)
  27.         
  28.         for e in entries:
  29.             e2 = grp.getgrgid(e.gr_gid)
  30.             self.check_value(e2)
  31.             self.assertEqual(e2.gr_gid, e.gr_gid)
  32.             e2 = grp.getgrnam(e.gr_name)
  33.             self.check_value(e2)
  34.             self.assertEqual(e2.gr_name, e.gr_name)
  35.         
  36.  
  37.     
  38.     def test_errors(self):
  39.         self.assertRaises(TypeError, grp.getgrgid)
  40.         self.assertRaises(TypeError, grp.getgrnam)
  41.         self.assertRaises(TypeError, grp.getgrall, 42)
  42.         bynames = { }
  43.         bygids = { }
  44.         for n, p, g, mem in grp.getgrall():
  45.             bynames[n] = g
  46.             bygids[g] = n
  47.         
  48.         allnames = bynames.keys()
  49.         namei = 0
  50.         fakename = allnames[namei]
  51.         while fakename in bynames:
  52.             chars = map(None, fakename)
  53.             for i in xrange(len(chars)):
  54.                 if chars[i] == 'z':
  55.                     chars[i] = 'A'
  56.                     break
  57.                     continue
  58.                 if chars[i] == 'Z':
  59.                     continue
  60.                     continue
  61.                 chars[i] = chr(ord(chars[i]) + 1)
  62.                 break
  63.             else:
  64.                 namei = namei + 1
  65.                 
  66.                 try:
  67.                     fakename = allnames[namei]
  68.                 except IndexError:
  69.                     break
  70.  
  71.             fakename = ''.join(map(None, chars))
  72.         self.assertRaises(KeyError, grp.getgrnam, fakename)
  73.         fakegid = 4127
  74.         while fakegid in bygids:
  75.             fakegid = fakegid * 3 % 65536
  76.         self.assertRaises(KeyError, grp.getgrgid, fakegid)
  77.  
  78.  
  79.  
  80. def test_main():
  81.     test_support.run_unittest(GroupDatabaseTestCase)
  82.  
  83. if __name__ == '__main__':
  84.     test_main()
  85.  
  86.